import java.util.*;

public class Main {

    public static void main1(String[] args) {
        PriorityQueue<Integer> que = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        while (scan.hasNextInt()) {
            int a = scan.nextInt();
            que.offer(a);
            int b = scan.nextInt();
            que.offer(b);
            int c = scan.nextInt();
            que.offer(c);

        }

        int j = n;
        while (j > 0) {
            que.poll();
            j--;
        }

        int num = 0;
        while (n > 0) {
            int sum = que.poll();
            num += sum;
            n--;
        }

        if (num > 10) {
            System.out.println(10);
        } else {
            System.out.println(num);
        }
    }




        public static void main(String[] args) {
            PriorityQueue<Integer> que = new PriorityQueue<>(new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return o2 - o1;
                }
            });
            Scanner scan = new Scanner(System.in);

            int n = scan.nextInt();
            int j = n;
            while(j > 0) {
                for (int i = 0; i < 3; i++) {
                    int index = scan.nextInt();
                    que.offer(index);
                }
                j--;
            }

            j = n;
            while(j > 0) {
                que.poll();
                j--;
            }

            int num = 0;
            while(n > 0) {
                int sum = que.poll();
                num += sum;
                n--;
            }

            System.out.println(num);
        }
}

